from rest_framework import serializers

import settings
from social.gift.models import Gift
from social.utils.serializers import HashidField


class GiftSerializer(serializers.ModelSerializer):
    id = HashidField(model=Gift)
    coin = serializers.IntegerField()
    name = serializers.CharField()
    thumb = serializers.SerializerMethodField()
    alpha = serializers.SerializerMethodField()

    def get_thumb(self, instance):
        return settings.IMAGE_HOST + instance.thumb

    def get_alpha(self, instance):
        request = self.context.get('request')
        if instance.type == 2:
            if request and request.user.is_vip:
                return 1
            else:
                return 0.7
        else:
            return 1

    class Meta:
        model = Gift
        fields = ('id', 'coin', 'name', 'thumb', 'alpha')
